-
Notifications
You must be signed in to change notification settings - Fork 354
feat: Long-running workers on Android devices #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
To view this pull requests documentation preview, visit the following URL: docs.page/fluttercommunity/flutter_workmanager~573 Documentation is deployed and generated using docs.page. |
|
@ened I Kindly ask for your input on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for building these features. I have left some comments
| /// The [taskName] is the value that will be returned in the [BackgroundTaskHandler] | ||
| /// The [inputData] is the input data for task. Valid value types are: int, bool, double, String and their list | ||
| Future<void> registerOneOffTask( | ||
| /// Only supported on Android. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably use default dart formatting 2-space indenting, so that it does not change the code which is not modified
| required this.notificationChannelDescription, | ||
| required this.notificationChannelImportance, | ||
| required this.notificationTitle, | ||
| required this.notificationDescription}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a trailing-comma and reformat, to be consistent
| package dev.fluttercommunity.workmanager | ||
|
|
||
| import android.content.Context | ||
| import android.content.pm.ServiceInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the import used?
| constraintsConfig = extractConstraintConfigFromCall(call), | ||
| outOfQuotaPolicy = extractOutOfQuotaPolicyFromCall(call), | ||
| backoffPolicyConfig = | ||
| extractBackoffPolicyConfigFromCall( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ened is this formatting ok, or it should be reverted. To not add unncessary changed lines and simplify reviews single formatting should be used
|
|
||
| export 'src/options.dart'; | ||
| export 'src/workmanager.dart' show Workmanager; | ||
| export 'src/workmanager.dart' show SetForegroundOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead do: export 'src/workmanager.dart' show Workmanager, SetForegroundOptions, etc;
This pull request introduces foreground service support on Android devices as per Android workmanager docs Support for long-running workers.
Foreground service support:
createForegroundInfoandcreateNotificationChannelinBackgroundWorker.ktto handle the creation of foreground notifications and channels.SetForegrounddata class andparseSetForegroundCallmethod inExtractor.ktto parse method calls related to setting foreground options. [1] [2]setForegroundmethod andSetForegroundOptionsclass inworkmanager.dartto set foreground options from Dart code. [1] [2]Code refactoring and improvements:
onMethodCallmethod inBackgroundWorker.ktto handle the newSET_FOREGROUNDmethod call.BackgroundWorker.ktandExtractor.kt. [1] [2]These changes allows tasks to run as foreground services.
This PR addresses issue #236, but goes against the recomendation on #511 of using
Workmanager.registerProcessingTaskto implement long-running wokers on android.Since the implementation of long-running workers on Android tightly depends on specific requirements such as handling notifications and activating a foreground service on the run, a decision was made to create a dedicated API which laverages ListenableWorker.serForegroundAsync and minimally handles notification management in order to implement long-running workers while following android guidelines.